﻿using AutoMapper;
using MediatR;
using Traceability.Commont.Domains;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;

namespace U.Enterprise.Api.Applications.Client
{
    public class ClientCreateHander:IRequestHandler<ClientCreateCommand,Resqults>
    {
        private readonly IBateRepository<Clients> clientBate;
        private readonly IMapper mapper;

        public ClientCreateHander(IBateRepository<Clients> clientBate, IMapper mapper)
        {
            this.clientBate = clientBate;
            this.mapper = mapper;
        }

        public async Task<Resqults> Handle(ClientCreateCommand request, CancellationToken cancellationToken)
        {
            try
            {
                Resqults res = new Resqults() { Code = 0 };
                Clients info=mapper.Map<Clients>(request);
                res.Code=await clientBate.Add(info);
                if (res.Code > 0)
                {
                    res.Messges = "成功";
                }
                return res;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
